/*===========================================================================================================================
	Wolf Prop Protection
		By Goluch
			DO NOT UPLOAD TO GARRYSMOD.ORG
			
			
	Section: CPPI
	Credits: Divran
===========================================================================================================================*/
WPP:RegisterAction("CPPI", "Cppi", "Interfacing for external addons.");
table.insert(WPP.Credits,"Divran")

if ( !CPPI ) then CPPI = {}; end
local CPPI = CPPI; -- Faster access
CPPI.NOTIMPLEMENTED = 1;
CPPI_NOTIMPLEMENTED = 1;
CPPI.DEFER = 2;
CPPI_DEFER = 2;

/*===========================================================================================================================
	Name: CPPI.GetName
	Purpose: CPPI Compatability.
	Author: Goluch, Divran
===========================================================================================================================*/
function CPPI:GetName()
	return "Wolf Prop Protection";
end

/*===========================================================================================================================
	Name: CPPI.GetName
	Purpose: CPPI Compatability.
	Author: Goluch, Divran
===========================================================================================================================*/
function CPPI:GetVersion()
	return tostring(WPP.Rev);
end

/*===========================================================================================================================
	Name: CPPI.GetInterfaceVersion
	Purpose: CPPI Compatability.
	Author: Goluch, Divran
===========================================================================================================================*/
function CPPI:GetInterfaceVersion()
	return 1.1;
end

/*===========================================================================================================================
	Name: CPPI.GetNameFromUID
	Purpose: CPPI Compatability.
	Author: Goluch, Divran
===========================================================================================================================*/
function CPPI:GetNameFromUID(uid)
	return CPPI.NOTIMPLEMENTED;
end

/*===========================================================================================================================
	Name: Player.CPPIGetFriends
	Purpose: CPPI Compatability.
	Author: Goluch, Divran
===========================================================================================================================*/
function _R.Player:CPPIGetFriends()
	local Friends = {};
	for _,Player in ipairs(player.GetAll()) do
		if( WPP:GetTrust(self,Player,WPP_CPPI) ) then
			Friends[#Friends+1] = Player;
		end
		
	end
	
	return Friends;
end

/*===========================================================================================================================
	Name: Entity.CPPIGetOwner
	Purpose: CPPI Compatability.
	Author: Goluch, Divran
===========================================================================================================================*/
function _R.Entity:CPPIGetOwner()
	
	if ( !WPP:IsOwned(self) ) then
		return nil, CPPI.NOTIMPLEMENTED;
	end
	
	local Player = WPP:GetOwner(self);
	
	if ( !Player ) or ( !Player:IsValid() ) then
		return nil, CPPI.NOTIMPLEMENTED;
	end
	
	return Player, Player:UniqueID();
end

/*===========================================================================================================================
	Name: Entity.CPPISetOwner
	Purpose: CPPI Compatability.
	Author: Goluch, Divran
===========================================================================================================================*/
if (SERVER) then
	function _R.Entity:CPPISetOwner(Player)
		if ( !Player ) or ( !Player:IsPlayer() ) then
			return false;
		end
		
		WPP:SetOwner(self,Player);
		return true;
	end
	
/*===========================================================================================================================
	Name: Entity.CPPISetOwnerUID
	Purpose: CPPI Compatability.
	Author: Goluch, Divran
===========================================================================================================================*/
	function _R.Entity:CPPISetOwnerUID(ID)
		if ( !ID ) then
			return false;
		end
		
		local Player = player.GetByUniqueID( tostring(ID) )
		if ( !Player ) or ( !Player:IsPlayer() ) then
			return false;
		end
		
		WPP:SetOwner(self,Player);
		return true;
	end
	
end

/*===========================================================================================================================
	Name: Entity.CPPICanTool
	Purpose: CPPI Compatability.
	Author: Goluch, Divran
===========================================================================================================================*/
function _R.Entity:CPPICanTool(Player,Mode)
	return WPP.CanTouch(Player,Player:GetEyeTrace(),Mode) or true;
end

/*===========================================================================================================================
	Name: Entity.CPPICanPhysgun
	Purpose: CPPI Compatability.
	Author: Goluch, Divran
===========================================================================================================================*/
function _R.Entity:CPPICanPhysgun(Player)
	return WPP.CanTouch(Player,Player:GetEyeTrace().Entity) or true;
end

/*===========================================================================================================================
	Name: Entity.CPPICanPickup
	Purpose: CPPI Compatability.
	Author: Goluch, Divran
===========================================================================================================================*/
function _R.Entity:CPPICanPickup(Player)
	return WPP.CanPickUp(Player,Player:GetEyeTrace().Entity) or true;
end

/*===========================================================================================================================
	Name: Entity.CPPICanPunt
	Purpose: CPPI Compatability.
	Author: Goluch, Divran
===========================================================================================================================*/
function _R.Entity:CPPICanPunt(Player)
	return WPP.CanPickUp(Player,Player:GetEyeTrace().Entity) or true;
end